<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <title>Document</title>
  <style>
    
  </style>
</head>
<body>
  
</body>
<script>

  // 类与类的继承


  function Parent(m){
    this.msg = m;
    this.show = function(){
      console.log(this.msg)
    }
  }
  Parent.prototype.init = function(){
    console.log("init")
  }

  function Parent2(){}
  Parent2.prototype.sayHi = function(){
    console.log("hi");
  }


  function Child(m){}
  // 浅拷贝
  // Child.prototype = Parent.prototype;
  // 注意深拷贝
  // for(let i in Parent.prototype){
  //   Child.prototype[i] = Parent.prototype[i];
  // }
  // for(let i in Parent2.prototype){
  //   Child.prototype[i] = Parent2.prototype[i];
  // }
  // 合并对象（深拷贝）
  Object.assign(Child.prototype, Parent.prototype);
  Object.assign(Child.prototype, Parent2.prototype);

  Child.prototype.init = function(){
    console.log("c的init")
  }

  const p = new Parent("hello");
  console.log(p);
  console.log(p.msg);
  p.show();
  p.init();

  const c = new Child("world");
  console.log(c)
  console.log(c.msg)
  // c.show();
  c.init();
  c.sayHi();

  
</script>
</html>